#ifndef SEARCHMANAGER_H
#define SEARCHMANAGER_H

#include <functional>
#include <memory>
#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QString>

// 用于管理搜索的类
// 因此只会做搜索相关的内容
// 解析等工作应该由回调函数完成
class SearchManager : public QObject
{
    Q_OBJECT
public:
    using callback = std::function<void(QByteArray)>;
public:
    static const SearchManager& getInstance()
    {
        static SearchManager manager;
        return manager;
    }
    void searchSongs(const QString& search_text, const callback& cb, int limit = 66, int offset = 0) const;
    void searchAlbum(int album_id, const callback& cb) const;
    void searchImage(const QString& image_url, const callback& cb) const;
    void searchLrc(qint64 song_id, const callback& cb) const;

    void checkUrl(const QString& song_url, const callback& cb) const;
private:
    explicit SearchManager() : _manager(new QNetworkAccessManager(this)) {}
    SearchManager(const SearchManager&) = delete;
    void search(const QString& urlStr, const callback& cb) const;

private:
    QNetworkAccessManager* _manager;
};

#endif // SEARCHMANAGER_H
